home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / misc / edu / globe099src.lha / Ami-Globe / IFF_FCT.C < prev    next >
C/C++ Source or Header  |  1994-11-04  |  12KB  |  386 lines

  1. /************************************************************************/
  2. /*                                                                      */
  3. /*      fichier         : iff_fct.c                                     */
  4. /*      projet          : amiglobe                                      */
  5. /*      date création   : juin 1994                                     */
  6. /*      commentaire     : fonctions relatives a l'affichage des images  */
  7. /*                        (fond, donnees externes, etc...)
  8. /*      révision        : $VER: iff_fct.c 1.003 (29 Sep 1994)
  9. /*      copyright       : Olivier Collard, Thomas Landspurg             */
  10. /*     $HISTORY:                                                */
  11. /*             juin        1994 : 0.01 : version initiale           */
  12. /*                                                                      */
  13. /************************************************************************/
  14.  
  15.  
  16. /************************************************************************/
  17. /*      includes                                                        */
  18. /************************************************************************/
  19. #include <exec/types.h>
  20. #include <exec/memory.h>
  21. #include <exec/libraries.h>
  22. #include <libraries/dos.h>
  23. #include <intuition/intuition.h>
  24. #include <graphics/gfxmacros.h>
  25. #include <graphics/displayinfo.h>
  26. #include <graphics/display.h>
  27. #include <datatypes/datatypes.h>
  28. #include <datatypes/datatypesclass.h>
  29. #include <datatypes/pictureclass.h>
  30. #include "iff/jiff.h"
  31.  
  32. /* Prototypes */
  33. #include <clib/alib_protos.h>
  34. #include <clib/exec_protos.h>
  35. #include <clib/dos_protos.h>
  36. #include <clib/graphics_protos.h>
  37. #include <clib/intuition_protos.h>
  38. #include <clib/datatypes_protos.h>
  39. #include <clib/macros.h>
  40.  
  41. /* ANSI C */
  42. #include <stdlib.h>
  43. #include <string.h>
  44. #include <stdio.h>
  45. #include <ctype.h>
  46. #include <stat.h>
  47. #include <math.h>
  48.  
  49. /************************************************************************/
  50. /*      variables externes                                              */
  51. /************************************************************************/
  52.  
  53. //extern  struct Library *IntuitionBase;
  54. extern  struct GfxBase  *GfxBase;
  55. extern  struct Library *DataTypeBase;
  56. extern  struct Screen * sC;
  57.  
  58. /************************************************************************/
  59. /*      variables privées                                               */
  60. /************************************************************************/
  61.  
  62. USHORT  palette_glob[32];
  63.  
  64. /************************************************************/
  65. /* Procedure to put the colors of the picture on the screen */
  66. /************************************************************/
  67.  
  68. void put_ea_cmap(unsigned   char    *cmap,int colors)
  69. {
  70.     int i;
  71.  
  72.     if (colors > MAXCOL)    /*color clipping*/
  73.         colors = MAXCOL;
  74.     for (i=0; i<colors; i++)
  75.     {
  76.         palette_glob[i] = 
  77.             ((cmap[0] & 0xf0) << 4) + (cmap[1] & 0xf0) + ((cmap[2] & 0xf0) >> 4);
  78.         cmap += 3;
  79.     }
  80. }
  81.  
  82. /***********************/
  83. /* Call the IFF loader */
  84. /***********************/
  85.  
  86. struct  Screen  *Iff_Charge_Iff(    char    *name)
  87. {
  88.     struct  ILBM_info   *info;
  89.     struct  RastPort    EcranRastPort;
  90.     struct  Screen  *s;
  91.     struct  Window  *win;
  92.     struct  RastPort    *rp;
  93.     static  struct TagItem    ScreenTags[8] = {
  94.     SA_Left,          0,
  95.     SA_Top,           0,
  96.     SA_Width,         320,
  97.     SA_Height,        200,
  98.     SA_Depth,         5,
  99.     SA_Type,          CUSTOMSCREEN,
  100.     SA_DisplayID,     PAL_MONITOR_ID,
  101.     TAG_DONE };
  102.  
  103.     InitRastPort(&EcranRastPort);
  104.     if ( (info = read_iff(name,0) ) != NULL){
  105.         ScreenTags[2].ti_Data=(ULONG)info->header.w;
  106.         ScreenTags[3].ti_Data=(ULONG)info->header.h;
  107.         ScreenTags[4].ti_Data=(ULONG)info->header.nPlanes;
  108.         ScreenTags[6].ti_Data=PAL_MONITOR_ID;
  109.         if(info->header.w>320){
  110.         ScreenTags[6].ti_Data|=MODE_640;
  111.         }
  112.         if(info->header.h>256){
  113.         ScreenTags[6].ti_Data|=INTERLACE;
  114.         }
  115.         if(info->header.nPlanes==6){
  116.         ScreenTags[6].ti_Data|=HOLDNMODIFY;
  117.         }
  118. /*
  119.         ScreenTags[6].ti_Data|=info->camg;
  120. */
  121.             if ( ( s = OpenScreenTagList( 0l, ScreenTags ))!=0){
  122.  
  123.             if(win=OpenWindowTags(
  124.                 NULL,
  125.                 WA_Left,    0,
  126.                 WA_Top,     0,
  127.                 WA_Width,   s->Width,
  128.                 WA_Height,  s->Height,
  129.                 WA_CustomScreen,s,
  130.                 WA_Flags,   WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_CLOSEGADGET,
  131.                 WA_IDCMP,   IDCMP_CLOSEWINDOW,
  132.                 TAG_DONE))
  133.         {
  134.             rp = win->RPort;
  135.             put_ea_cmap(&info->cmap,32 );
  136.             EcranRastPort.BitMap = &info->bitmap;
  137.             ClipBlit( &EcranRastPort, 0L, 0L,
  138.                 rp, 0L, 0L,
  139.                 (rp->BitMap->BytesPerRow)*8,
  140.                 rp->BitMap->Rows, (long)COPY_MINTERM);
  141.         }else{
  142.             CloseScreen(s);
  143.             s=NULL;
  144.         }
  145.         }
  146.         free_planes(&info->bitmap);
  147.     }else{
  148.         Aff_Error("ERROR loading IFF file\n","OK");
  149.     }
  150.     return(s);
  151. }
  152.  
  153. /*********************************************************/
  154. Object *Iff_New_Charge_Iff(char *pc,struct Screen *In_Scr)
  155. {
  156.     ULONG *cregs = NULL, numcolors, i, r, g, b;
  157.     struct dtFrameBox dtf = {NULL};
  158.     struct FrameInfo fri = {NULL};
  159.     struct BitMapHeader *bmhd;
  160.     ULONG modeid = INVALID_ID;
  161.     struct gpLayout gpl;
  162.     struct BitMap *bm;
  163.     struct RastPort rp;
  164.     Object *o;
  165.  
  166.  
  167.     o=0;
  168.     if (DataTypeBase){
  169.  
  170.         /* Obtain a pointer to the picture object */
  171.         if (o = NewDTObject ((APTR) pc,
  172.                      DTA_SourceType, DTST_FILE,
  173.                      DTA_GroupID, GID_PICTURE,
  174.                      PDTA_Remap, FALSE,
  175.                      TAG_DONE))
  176.         {
  177.             /* Ask the object what kind of environment it needs */
  178.             dtf.MethodID = DTM_FRAMEBOX;
  179.             dtf.dtf_FrameInfo = &fri;
  180.             dtf.dtf_ContentsInfo = &fri;
  181.             dtf.dtf_SizeFrameInfo = sizeof (struct FrameInfo);
  182.             if (DoMethodA (o, &dtf) && fri.fri_Dimensions.Depth)
  183.             {
  184.  
  185.             /* Layout the object on our process */
  186.             gpl.MethodID = DTM_PROCLAYOUT;
  187.             gpl.gpl_GInfo = NULL;
  188.             gpl.gpl_Initial = 1;
  189.             if (DoMethodA (o, &gpl))
  190.             {
  191.                 /* Get the object information */
  192.                 GetDTAttrs (o,
  193.                     PDTA_ModeID, &modeid,
  194.                     PDTA_CRegs, &cregs,
  195.                     PDTA_NumColors, &numcolors,
  196.                     PDTA_BitMapHeader, &bmhd,
  197.                     PDTA_BitMap, &bm,
  198.                     TAG_DONE);
  199.  
  200.                 /* Make sure we have a bitmap to attach to the screen */
  201.                 if (bm)
  202.                 {
  203.                     InitRastPort(&rp);
  204.                         rp.BitMap=bm;
  205.                     /* Load the color map */
  206.                     if (cregs)
  207.                     {
  208.                       if(In_Scr!=NULL){
  209.                     numcolors = 2 << (In_Scr->RastPort.BitMap->Depth - 1);
  210.                     for (i = 0; i < numcolors; i++)
  211.                     {
  212.                         r = cregs[i * 3 + 0];
  213.                         g = cregs[i * 3 + 1];
  214.                         b = cregs[i * 3 + 2];
  215.                         SetRGB32 (&In_Scr->ViewPort, i, r, g, b);
  216.                     }
  217.                       }
  218.                     }
  219.  
  220.                 }else{
  221.                     Aff_Error("ERROR opening screen\n(not enough chip memory)\n","OK");
  222.                 }
  223.             }
  224.             }else{
  225.             Aff_Error("This is not a displayable picture\n","Too Bad");
  226.             }
  227.         }
  228.     }else{
  229.         Aff_Error("This function requires WB3.0 (Datatypes) to work!","Shit");
  230. /*
  231.         scr=Charge_Iff(pc);
  232. */
  233.     }
  234.     return(o);
  235. }
  236.  
  237. void    Iff_Free_Obj(Object *o)
  238. {
  239.     if(o!=NULL){
  240.         if (DataTypeBase){
  241.     
  242.             /* Get rid of the object */
  243.                 DisposeDTObject (o);
  244.  
  245.         }else{
  246.         }
  247.     }
  248. }
  249.  
  250.  
  251. void    Iff_Copy_Fond(Object *o,struct RastPort *rpG)
  252. {
  253.     struct BitMapHeader *bmhd;
  254.     ULONG modeid = INVALID_ID;
  255.     struct BitMap *bm;
  256.     struct RastPort rp;
  257.  
  258.  
  259.     if ((DataTypeBase)&&(o!=NULL)){
  260.  
  261.         /* Get the object information */
  262.         GetDTAttrs (o,
  263.             PDTA_ModeID, &modeid,
  264.             PDTA_BitMapHeader, &bmhd,
  265.             PDTA_BitMap, &bm,
  266.             TAG_DONE);
  267.  
  268.         /* Make sure we have a bitmap to attach to the screen */
  269.         if (bm)
  270.         {
  271.             long dest_x=0;
  272.             long dest_y=0;
  273.             InitRastPort(&rp);
  274.                 rp.BitMap=bm;
  275.             while (dest_x<sC->Width)
  276.             {
  277.                 /*printf("dest_x=%d\n",dest_x);*/
  278.                 while (dest_y<sC->Height)
  279.                 {
  280.                     ClipBlit( &rp, 0L, 0L,
  281.                             rpG, dest_x, dest_y,
  282.                             bmhd->bmh_Width, /*bm->BytesPerRow*8/bm->Depth,*/
  283.                             bmhd->bmh_Height, /*bm->Rows*/
  284.                             (long)COPY_MINTERM);
  285.                     dest_y+=bmhd->bmh_Height;/*bm->Rows;*/
  286.                 }
  287.                 dest_y=0;
  288.                 dest_x+=bmhd->bmh_Width;/*bm->BytesPerRow*8/bm->Depth;*/
  289.             }
  290.          }
  291.       
  292.       }
  293. }
  294.  
  295.  
  296.  
  297. /*********************************************************/
  298. struct  Screen *Iff_Load_And_Open(char *pc)
  299. {
  300.     struct dtFrameBox dtf = {NULL};
  301.     struct FrameInfo fri = {NULL};
  302.     struct BitMapHeader *bmhd;
  303.     ULONG modeid = INVALID_ID;
  304.     struct Screen *scr;
  305.     struct Window *win;
  306.     struct BitMap *bm;
  307.     struct RastPort rp;
  308.     ULONG *cregs = NULL, numcolors, i, r, g, b;
  309.     Object *o;
  310.  
  311.     scr=NULL;
  312.     o=Iff_New_Charge_Iff(pc,NULL);
  313.     if(o){  
  314.         /* Ask the object what kind of environment it needs */
  315.         dtf.MethodID = DTM_FRAMEBOX;
  316.         dtf.dtf_FrameInfo = &fri;
  317.         dtf.dtf_ContentsInfo = &fri;
  318.         dtf.dtf_SizeFrameInfo = sizeof (struct FrameInfo);
  319.         if (DoMethodA (o, &dtf) && fri.fri_Dimensions.Depth)
  320.         {
  321.             /* Get the object information */
  322.             GetDTAttrs (o,
  323.                 PDTA_ModeID, &modeid,
  324.                 PDTA_CRegs, &cregs,
  325.                 PDTA_NumColors, &numcolors,
  326.                 PDTA_BitMapHeader, &bmhd,
  327.                 PDTA_BitMap, &bm,
  328.                 TAG_DONE);
  329.  
  330.             /* Make sure we have a bitmap to attach to the screen */
  331.             if (bm)
  332.             {
  333.             /* Open the screen */
  334.             if (scr = OpenScreenTags (NULL,
  335.                   SA_Width, (ULONG) fri.fri_Dimensions.Width,
  336.                   SA_Height, (ULONG) fri.fri_Dimensions.Height,
  337.                   SA_Depth, (ULONG) fri.fri_Dimensions.Depth,
  338.                   SA_DisplayID, modeid,
  339.                   SA_ShowTitle, FALSE,
  340.                   SA_Quiet, TRUE,
  341.                   SA_Behind, TRUE,
  342.                   TAG_DONE))
  343.             {
  344.                 InitRastPort(&rp);
  345.                     rp.BitMap=bm;
  346.  
  347.                 if(win=OpenWindowTags(
  348.                 NULL,
  349.                 WA_Left,    0,
  350.                 WA_Top,     0,
  351.                 WA_Width,   scr->Width,
  352.                 WA_Height,  scr->Height,
  353.                 WA_CustomScreen,scr,
  354.                 WA_Flags,   WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_CLOSEGADGET,
  355.                 WA_IDCMP,   IDCMP_CLOSEWINDOW,
  356.                 TAG_DONE))
  357.                 {
  358.                         ClipBlit( &rp, 0L, 0L,
  359.                           win->RPort, 0L, 0L,
  360.                           fri.fri_Dimensions.Width,
  361.                           fri.fri_Dimensions.Height,
  362.                           (long)COPY_MINTERM);
  363.                 /* Load the color map */
  364.                 if (cregs)
  365.                 {
  366.                 numcolors = 2 << (scr->RastPort.BitMap->Depth - 1);
  367.                 for (i = 0; i < numcolors; i++)
  368.                 {
  369.                     r = cregs[i * 3 + 0];
  370.                     g = cregs[i * 3 + 1];
  371.                     b = cregs[i * 3 + 2];
  372.                     SetRGB32 (&scr->ViewPort, i, r, g, b);
  373.                 }
  374.                 }
  375.                 }
  376.                 /* Bring the screen to the front now */
  377.                 ScreenToFront (scr);
  378.             }
  379.             }
  380.         }
  381.         /* Get rid of the object */
  382.             DisposeDTObject (o);
  383.     }
  384.     return(scr);
  385. }
  386.